const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const TableColumn = sequelize.define('TableColumn', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    table_config_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '表格配置ID'
    },
    key: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '列键值'
    },
    title: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '列标题'
    },
    data_index: {
      type: DataTypes.JSON,
      comment: '数据索引路径'
    },
    width: {
      type: DataTypes.INTEGER,
      comment: '列宽'
    },
    fixed: {
      type: DataTypes.ENUM('left', 'right'),
      comment: '固定位置'
    },
    searchable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否可搜索'
    },
    sortable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否可排序'
    },
    filterable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否可筛选'
    },
    copyable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否可复制'
    },
    ellipsis: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否省略显示'
    },
    required: {
      type: DataTypes.BOOLEAN,
      defaultValue: false,
      comment: '是否必填'
    },
    value_type: {
      type: DataTypes.ENUM('text', 'number', 'currency', 'date', 'datetime', 'tag', 'select', 'boolean'),
      defaultValue: 'text',
      comment: '值类型'
    },
    render_type: {
      type: DataTypes.STRING(50),
      comment: '渲染类型'
    },
    sort_order: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      comment: '排序顺序'
    },
    visible: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      comment: '是否可见'
    },
    status: {
      type: DataTypes.ENUM('active', 'inactive'),
      defaultValue: 'active',
      comment: '状态'
    }
  }, {
    tableName: 'table_columns',
    comment: '动态表格列配置表'
  })

  return TableColumn
}